/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Schedule.java
 *
 * Created on May 5, 2011, 9:20:41 PM
 */

package c0907m.group2.aitsm.gui;

import c0907m.group2.aitsm.core.db.*;
import c0907m.group2.aitsm.core.entity.ClassInfo;
import c0907m.group2.aitsm.core.entity.ScheduleInfo;
import c0907m.group2.aitsm.core.entity.SubjectInfo;
import c0907m.group2.aitsm.core.entity.UserInfo;
import c0907m.group2.aitsm.core.report.ScheduleReporter;
import c0907m.group2.aitsm.gui.component.DateTimeCellRenderer;
import c0907m.group2.aitsm.gui.component.DefaultPanel;
import c0907m.group2.aitsm.gui.component.StatusBar;
import c0907m.group2.aitsm.gui.handler.InvalidEditEvent;
import c0907m.group2.aitsm.gui.handler.InvalidEditListener;
import c0907m.group2.aitsm.gui.handler.TableCellListener;
import c0907m.group2.aitsm.util.DateSynchronizer;
import c0907m.group2.aitsm.util.Helper;
import c0907m.group2.aitsm.util.Settings;
import com.standbysoft.component.date.swing.JDatePicker;
import com.standbysoft.component.date.swing.plaf.basic.SpinnerTimePickerUI;
import net.sf.jasperreports.engine.JRException;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author ISTC
 */
@SuppressWarnings({"ALL"})
public class Schedule extends DefaultPanel {
    //default state on status bar when init
    public static final String DEFAULT_STATUS = "Add, update, delete schedules";
    public static final String DATE_FORMAT = "MMM dd, yyyy hh:mm a";
    public final Logger logger = Logger.getLogger(Schedule.class.getName());
    private DefaultTableModel dtm;
    private StatusBar statusBar;
    private List<ScheduleInfo> editingList;
    private List<ClassInfo> allClasses;
    private List<SubjectInfo> allSubjects;
    private List<UserInfo> allUsers;
    private List<Integer> userIDs;
    private List<Integer> subjectIDs;
    private List<Integer> classIDs;
    private ScheduleDb scheduleDB;
    private JComboBox cboClassEditor;
    private JComboBox cboUserEditor;
    private JComboBox cboSubjectEditor;
    private DefaultCellEditor classEditor;
    private DefaultCellEditor userEditor;
    private DefaultCellEditor subjectEditor;
    private List<Integer> sbjFromCourse;
    private List<Integer> usersFromSubject;

    public void setStatusBar(StatusBar sb) {
        this.statusBar = sb;
    }

    /**
     * Creates new form Schedule
     */
    public Schedule() {
        initComponents();
        btnUpdate.setEnabled(false);
        statusBar = new StatusBar();
        scheduleDB = new ScheduleDb();
        editingList = new ArrayList<ScheduleInfo>();
        dtm = (DefaultTableModel) tblScheduleList.getModel();
        cboClassEditor = new JComboBox();
        cboUserEditor = new JComboBox();
        cboSubjectEditor = new JComboBox();
        loadDataToComboBox();
        loadSchedulesToTable();
        tblScheduleListEventHandler();
    }

    public void addInvalidEditListener(InvalidEditListener l) {
        listenerList.add(InvalidEditListener.class, l);
    }

    public void removeInvalidEditListener(InvalidEditListener l) {
        listenerList.remove(InvalidEditListener.class, l);
    }

    private void fireInvalidEditEvent(InvalidEditEvent evt) {
        Object[] listeners = listenerList.getListenerList();

        for (int i = 0; i < listeners.length; i += 2) {
            if (listeners[i] == InvalidEditListener.class) {
                ((InvalidEditListener) listeners[i + 1]).invalidEdited(evt);
            }
        }
    }

    /**
     * Reload all data from database
     */
    @Override
    public void refresh() {
        if (dtm.getRowCount() > 0) dtm.setRowCount(0);
        doReset();
        loadSchedulesToTable();
    }

    /**
     * Update changes
     */
    @Override
    public void doUpdate() {
        if (editingList.isEmpty()) {
            statusBar.setMessage("No changes have been made: Update cancelled.", StatusBar.WARNING_TYPE);
            return;
        }

        try {
            scheduleDB.update(editingList);
            statusBar.setMessage("Update successful.", StatusBar.MESSAGE_TYPE);
        } catch (SQLException e) {
            logger.log(Level.WARNING, "Update failed: " + e.getMessage());
            statusBar.setMessage("Update failed.", StatusBar.ERROR_TYPE);
            refresh();
        }

        editingList.removeAll(editingList);
    }

    /**
     * Add new Schedule to database
     */
    @Override
    public void doAdd() {
        long startTime = Helper.toDate(dpStart.getText(), DATE_FORMAT).getTime();
        long endTime = Helper.toDate(dpEnd.getText(), DATE_FORMAT).getTime();

        int classId = allClasses
                .get(cboClass.getSelectedIndex())
                .getId();
        int subjectId = sbjFromCourse
                .get(cboSubject.getSelectedIndex());
        int userId = usersFromSubject
                .get(cboUser.getSelectedIndex());

        ScheduleInfo newSchedule = new ScheduleInfo();
        newSchedule.setStartTime(new java.sql.Date(startTime));
        newSchedule.setEndTime(new java.sql.Date(endTime));
        newSchedule.setClassId(classId);
        newSchedule.setUserId(userId);
        newSchedule.setSubjectId(subjectId);

        try {
            scheduleDB.insert(newSchedule);
            statusBar.setMessage("Schedule added", StatusBar.MESSAGE_TYPE);
            refresh();
        } catch (SQLException ex) {
            logger.log(Level.SEVERE, ex.getMessage());
            statusBar.setMessage("Adding failed.", StatusBar.ERROR_TYPE);
        }
    }

    /**
     * Reset all fields to blank
     */
    @Override
    public void doReset() {

    }

    /**
     * Search function
     */
    public void doSearch() {
        if (dtm.getRowCount() > 0) dtm.setRowCount(0);
        List<ScheduleInfo> result = null;

        String strStartTime = dpStartSearch.getText();
        String strEndTime = dpStartSearch.getText();
        String subjectName = txtSubject.getText().trim();
        String userName = txtUser.getText().trim();
        String className = txtClass.getText().trim();
        int subjectId = 0;
        int userId = 0;
        int classId = 0;
        boolean foundSubject = subjectName.equals("");
        boolean foundUser = userName.equals("");
        boolean foundClass = className.equals("");

        for (SubjectInfo i : allSubjects)
            if (i.getName().equalsIgnoreCase(subjectName)) {
                subjectId = i.getId();
                foundSubject = true;
            }

        for (ClassInfo i : allClasses)
            if (i.getName().equalsIgnoreCase(className)) {
                classId = i.getId();
                foundClass = true;
            }

        for (UserInfo i : allUsers)
            if (i.getName().equalsIgnoreCase(userName)) {
                userId = i.getId();
                foundUser = true;
            }

        if (foundClass == false || foundSubject == false || foundUser == false) {
            statusBar.setMessage("No match found.", StatusBar.MESSAGE_TYPE);
            return;
        }

        Date startTime = (strStartTime.equals("") | strStartTime.equals("   ,  ")) ? null : Helper.toDate(strStartTime, DATE_FORMAT);
        Date endTime = (strEndTime.equals("") | strStartTime.equals("   ,  ")) ? null : Helper.toDate(strEndTime, DATE_FORMAT);

        try {
            result = scheduleDB.select(subjectId, classId, userId, startTime, endTime);

            if (result.isEmpty()) {
                statusBar.setMessage("No match found.", StatusBar.MESSAGE_TYPE);
            } else {
                addDataToTable(result);
                statusBar.setMessage(result.size() + " match(es) found.", StatusBar.MESSAGE_TYPE);
            }
        } catch (SQLException e) {
            logger.log(Level.WARNING, e.getSQLState());
            statusBar.setMessage("Search stopped.", StatusBar.ERROR_TYPE);
        }

    }


    /**
     * Load all Schedules from database to table when initialize
     */
    private void loadSchedulesToTable() {
        classEditor = Helper.addComboBoxToTable(tblScheduleList, cboClassEditor, 1);
        userEditor = Helper.addComboBoxToTable(tblScheduleList, cboUserEditor, 3);
        subjectEditor = Helper.addComboBoxToTable(tblScheduleList, cboSubjectEditor, 2);

        JDatePicker datePicker = new JDatePicker();
        datePicker.putClientProperty("JDatePicker.TimePickerUI", SpinnerTimePickerUI.class.getName());
        datePicker.putClientProperty("JDatePicker.showTimePicker", Boolean.TRUE);
        datePicker.setEditable(true);
        datePicker.setDateFormat("MM/dd/yy hh:mm a");
        tblScheduleList.setDefaultEditor(java.util.Date.class, JDatePicker.createTableCellEditor(datePicker));
        tblScheduleList.setDefaultRenderer(java.util.Date.class, new DateTimeCellRenderer());

        scheduleDB = new ScheduleDb();
        List<ScheduleInfo> scheduleList = null;
        try {
            scheduleList = scheduleDB.select();
        } catch (SQLException ex) {
            logger.log(Level.SEVERE, ex.getMessage());
            statusBar.setMessage("Unable to load data.", StatusBar.WARNING_TYPE);
        }

        addDataToTable(scheduleList);
    }

    /**
     * Add data from a list of schedules into table
     *
     * @param result list to add
     */
    private void addDataToTable(List<ScheduleInfo> result) {
        classIDs = new ArrayList<Integer>();
        userIDs = new ArrayList<Integer>();
        subjectIDs = new ArrayList<Integer>();

        try {
            for (ScheduleInfo r : result) {
                String className = new ClassDb().select(r.getClassId()).getName();
                cboClassEditor = (JComboBox) classEditor.getComponent();
                cboClassEditor.setSelectedItem(className);

                String subjectName = new SubjectDb().select(r.getSubjectId()).getName();
                cboSubjectEditor = (JComboBox) subjectEditor.getComponent();
                cboSubjectEditor.setSelectedItem(subjectName);

                String userName = new UserDb().select(r.getUserId()).getName();
                cboUserEditor = (JComboBox) userEditor.getComponent();
                cboUserEditor.setSelectedItem(userName);

                dtm.addRow(new Object[]{
                        r.getId(),
                        //classEditor.getCellEditorValue(),
                        //subjectEditor.getCellEditorValue(),
                        //userEditor.getCellEditorValue(),
                        cboClassEditor.getSelectedItem(),
                        cboSubjectEditor.getSelectedItem(),
                        cboUserEditor.getSelectedItem(),
                        r.getStartTime(),
                        r.getEndTime()
                });

                classIDs.add(r.getClassId());
                subjectIDs.add(r.getSubjectId());
                userIDs.add(r.getUserId());
            }
        } catch (SQLException ex) {
            logger.log(Level.SEVERE, null, ex.getSQLState());
            statusBar.setMessage("Unable to load data", StatusBar.ERROR_TYPE);
        }
    }

    /**
     * Load all data to all combobox that is used in this form
     */
    private void loadDataToComboBox() {
        new DateSynchronizer(cboDayDlg, cboMonthDlg, cboYearDlg, 0, 2);

        try {
            allUsers = new UserDb().select();
            allSubjects = new SubjectDb().select();
            allClasses = new ClassDb().select();
            List<UserInfo> activeUser = new ArrayList<UserInfo>();
            List<SubjectInfo> activeSubject = new ArrayList<SubjectInfo>();
            List<ClassInfo> activeClass = new ArrayList<ClassInfo>();

            for (ClassInfo ci : allClasses) {
                if (ci.isActive()) {
                    cboClass.addItem(ci.getName());
                    cboClassEditor.addItem(ci.getName());
                    activeClass.add(ci);
                }
            }
            allClasses = activeClass;

            for (UserInfo i : allUsers) {
                if (i.isActive()) {
                    cboUserEditor.addItem(i.getName());
                    activeUser.add(i);
                }
            }
            allUsers = activeUser;

            for (SubjectInfo i : allSubjects) {
                if (i.isActive()) {
                    cboSubjectEditor.addItem(i.getName());
                    activeSubject.add(i);
                }
            }
            allSubjects = activeSubject;

            cboClass.setSelectedIndex(0);
            //generateSubjectFromClass();

            cboSubject.setSelectedIndex(0);
            //generateUserFromSubject();

        } catch (SQLException ex) {
            logger.log(Level.SEVERE, ex.getSQLState());
            statusBar.setMessage("Unable to load data.", StatusBar.ERROR_TYPE);
        }
    }

    /**
     * Generate subject from class
     */
    private void generateSubjectFromClass() {
        //.removeActionListener(subjectListener);
        try {
            List<Integer> activeSId = new ArrayList<Integer>();
            int courseId = allClasses.get(cboClass.getSelectedIndex()).getCourseId();
            sbjFromCourse = new CourseSubjectDb().select(courseId, CourseSubjectDb.COURSE);
            for (int sbjId : sbjFromCourse) {
                if (new SubjectDb().select(sbjId).isActive()) {
                    cboSubject.addItem(new SubjectDb().select(sbjId).getName());
                    activeSId.add(sbjId);
                }
            }

            sbjFromCourse = activeSId;
        } catch (SQLException ex) {
            Logger.getLogger(Schedule.class.getName()).log(Level.SEVERE, null, ex);
        }
        //cboSubject.addActionListener(subjectListener);
    }

    /**
     * Generate user from subject
     */
    private void generateUserFromSubject() {
        try {
            if (cboSubject.getSelectedIndex() != -1) {
                List<Integer> activeUId = new ArrayList<Integer>();
                usersFromSubject = new UserSubjectDb()
                        .select(sbjFromCourse.get(
                                cboSubject.getSelectedIndex()
                        ), UserSubjectDb.SUBJECT);
                for (int uId : usersFromSubject) {
                    if (new UserDb().select(uId).isActive()) {
                        cboUser.addItem(new UserDb().select(uId).getName());
                        activeUId.add(uId);
                    }
                }
                usersFromSubject = activeUId;
            }
        } catch (SQLException ex) {
            Logger.getLogger(Schedule.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void tblScheduleListEventHandler() {
        tblScheduleListCellHandler();
        tblScheduleListRowSorter();
    }

    public void tblScheduleListCellHandler() {
        Action action = new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                btnUpdate.setEnabled(true);
                TableCellListener tcl = (TableCellListener) e.getSource();

                int row = tcl.getRow();
                int column = tcl.getColumn();

                ScheduleInfo scheduleToUpdate = new ScheduleInfo();

                Date startTime = (Date) dtm.getValueAt(row, 4);
                Date endTime = (Date) dtm.getValueAt(row, 5);


                try {
                    if (column == 1) {
                        //check if subject belongs to this course or not
                        boolean validSubject = false;
                        int courseId = allClasses.get(cboClassEditor.getSelectedIndex()).getCourseId();
                        sbjFromCourse = new CourseSubjectDb().select(courseId, CourseSubjectDb.COURSE);
                        for (int subjectId : sbjFromCourse) {
                            if (subjectId == subjectIDs.get(row)) {
                                validSubject = true;
                            }
                        }

                        if (!validSubject) {
                            int confirm = JOptionPane.showConfirmDialog(
                                    null,
                                    "This class does not currently have "
                                            + (String) dtm.getValueAt(row, 2)
                                            + " subject right now."
                                            + " Would you like to update this subject for this class?",
                                    "Warning",
                                    JOptionPane.YES_NO_OPTION
                            );

                            if (confirm == JOptionPane.YES_OPTION) {
                                fireInvalidEditEvent(new InvalidEditEvent(Subject.class));
                            } else {
                                dtm.setValueAt(tcl.getOldValue(), row, column);
                                return;
                            }
                        }

                        scheduleToUpdate.setId((Integer) dtm.getValueAt(row, 0));
                        scheduleToUpdate.setStartTime(
                                new java.sql.Date(startTime.getTime())
                        );
                        scheduleToUpdate.setEndTime(
                                new java.sql.Date(endTime.getTime())
                        );

                        //cboClassEditor = (JComboBox) classEditor.getComponent();
                        scheduleToUpdate.setClassId(
                                allClasses.get(cboClassEditor.getSelectedIndex())
                                        .getId()
                        );

                        //cboUserEditor = (JComboBox) userEditor.getComponent();
                        scheduleToUpdate.setUserId(userIDs.get(row));

                        //cboSubjectEditor = (JComboBox) subjectEditor.getComponent();
                        scheduleToUpdate.setSubjectId(subjectIDs.get(row));

                        classIDs.set(row, allClasses.get(cboClassEditor.getSelectedIndex())
                                .getId());
                        //System.out.println(scheduleToUpdate.toString());
                    } else if (column == 2) {
                        //check if subject belongs to this course or not
                        boolean validSubject = false;
                        int courseId = new ClassDb().select(classIDs.get(row)).getCourseId();
                        sbjFromCourse = new CourseSubjectDb().select(courseId, CourseSubjectDb.COURSE);
                        for (int subjectId : sbjFromCourse) {
                            if (subjectId == allSubjects.get(cboSubjectEditor.getSelectedIndex())
                                    .getId()) {
                                validSubject = true;
                            }
                        }

                        //check if subject belongs to this user or not
                        boolean validUser = false;
                        usersFromSubject = new UserSubjectDb().select(allSubjects.get(cboSubjectEditor.getSelectedIndex())
                                    .getId(), UserSubjectDb.SUBJECT);
                        for (int userId : usersFromSubject) {
                            if (userId == userIDs.get(row)) {
                                validUser = true;
                            }
                        }

                        if (!validSubject && !validUser) {
                            JOptionPane.showMessageDialog(
                                    null,
                                    "WARNING: This subject is not belongs to any course or user," +
                                            " please go to Course-Subject and User-Subject section to manage."

                            );
                            dtm.setValueAt(tcl.getOldValue(), row, column);
                            return;
                        }
                        else if (!validSubject) {
                            int confirm = JOptionPane.showConfirmDialog(
                                    null,
                                    "This class does not currently have "
                                            + (String) dtm.getValueAt(row, 2)
                                            + " subject right now."
                                            + " Would you like to update this subject for this class?",
                                    "Warning",
                                    JOptionPane.YES_NO_OPTION
                            );

                            if (confirm == JOptionPane.YES_OPTION) {
                                fireInvalidEditEvent(new InvalidEditEvent(Subject.class));
                            } else {
                                dtm.setValueAt(tcl.getOldValue(), row, column);
                                return;
                            }
                        }
                        else if (!validUser) {
                            int confirm = JOptionPane.showConfirmDialog(
                                    null,
                                    "This user is not currently teaching "
                                            + (String) dtm.getValueAt(row, 2)
                                            + " subject right now."
                                            + " Would you like to update this subject for this user?",
                                    "Warning",
                                    JOptionPane.YES_NO_OPTION
                            );

                            if (confirm == JOptionPane.YES_OPTION) {
                                fireInvalidEditEvent(new InvalidEditEvent(User.class));
                            } else {
                                dtm.setValueAt(tcl.getOldValue(), row, column);
                                return;
                            }
                        }

                        scheduleToUpdate.setId((Integer) dtm.getValueAt(row, 0));
                        scheduleToUpdate.setStartTime(
                                new java.sql.Date(startTime.getTime())
                        );
                        scheduleToUpdate.setEndTime(
                                new java.sql.Date(endTime.getTime())
                        );

                        //cboClassEditor = (JComboBox) classEditor.getComponent();
                        scheduleToUpdate.setSubjectId(
                                allSubjects.get(cboSubjectEditor.getSelectedIndex())
                                        .getId()
                        );

                        //cboUserEditor = (JComboBox) userEditor.getComponent();
                        scheduleToUpdate.setUserId(userIDs.get(row));

                        //cboSubjectEditor = (JComboBox) subjectEditor.getComponent();
                        scheduleToUpdate.setClassId(classIDs.get(row));

                        subjectIDs.set(row, allSubjects.get(cboSubjectEditor.getSelectedIndex())
                                .getId());
                        //System.out.println(scheduleToUpdate.toString());
                    } else if (column == 3) {
                        //check if subject belongs to this user or not
                        boolean validUser = false;
                        usersFromSubject = new UserSubjectDb().select(subjectIDs.get(row), UserSubjectDb.SUBJECT);
                        for (int userId : usersFromSubject) {
                            if (userId == allUsers.get(cboUserEditor.getSelectedIndex())
                                    .getId()) {
                                validUser = true;
                            }
                        }
                        if (!validUser) {
                            int confirm = JOptionPane.showConfirmDialog(
                                    null,
                                    "This user is not currently teaching "
                                            + (String) dtm.getValueAt(row, 2)
                                            + " subject right now."
                                            + " Would you like to update this subject for this user?",
                                    "Warning",
                                    JOptionPane.YES_NO_OPTION
                            );

                            if (confirm == JOptionPane.YES_OPTION) {
                                fireInvalidEditEvent(new InvalidEditEvent(User.class));
                            } else {
                                dtm.setValueAt(tcl.getOldValue(), row, column);
                                return;
                            }
                        }

                        scheduleToUpdate.setId((Integer) dtm.getValueAt(row, 0));
                        scheduleToUpdate.setStartTime(
                                new java.sql.Date(startTime.getTime())
                        );
                        scheduleToUpdate.setEndTime(
                                new java.sql.Date(endTime.getTime())
                        );

                        //cboClassEditor = (JComboBox) classEditor.getComponent();
                        scheduleToUpdate.setUserId(
                                allUsers.get(cboUserEditor.getSelectedIndex())
                                        .getId()
                        );

                        //cboUserEditor = (JComboBox) userEditor.getComponent();
                        scheduleToUpdate.setClassId(classIDs.get(row));

                        //cboSubjectEditor = (JComboBox) subjectEditor.getComponent();
                        scheduleToUpdate.setSubjectId(subjectIDs.get(row));

                        userIDs.set(row, allUsers.get(cboUserEditor.getSelectedIndex())
                                .getId());

                    } else {
                        scheduleToUpdate.setId((Integer) dtm.getValueAt(row, 0));
                        scheduleToUpdate.setStartTime(
                                new java.sql.Date(startTime.getTime())
                        );
                        scheduleToUpdate.setEndTime(
                                new java.sql.Date(endTime.getTime())
                        );


                        //cboClassEditor = (JComboBox) classEditor.getComponent();
                        scheduleToUpdate.setUserId(userIDs.get(row));

                        //cboUserEditor = (JComboBox) userEditor.getComponent();
                        scheduleToUpdate.setClassId(classIDs.get(row));

                        //cboSubjectEditor = (JComboBox) subjectEditor.getComponent();
                        scheduleToUpdate.setSubjectId(subjectIDs.get(row));
                    }

                    //System.out.println(scheduleToUpdate.toString());
                    editingList.add(scheduleToUpdate);
                } catch (NumberFormatException e1) {
                    JOptionPane.showMessageDialog(
                            null,
                            "Wrong format!",
                            "Warning",
                            JOptionPane.ERROR_MESSAGE
                    );
                    dtm.setValueAt(tcl.getOldValue(), row, column);
                } catch (Exception e2) {
                    logger.log(Level.SEVERE, null, e2);
                    statusBar.setMessage("Unknown", StatusBar.ERROR_TYPE);
                }

                //System.out.println("Event fired!");
            }
        };

        TableCellListener tcl = new TableCellListener(tblScheduleList, action);
    }

    public void tblScheduleListRowSorter() {
        RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(dtm);
        tblScheduleList.setRowSorter(sorter);
    }

    /**
     * This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dlgReport = new javax.swing.JDialog();
        pnReport = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        pnToggle = new javax.swing.JPanel();
        cboMonthDlg = new javax.swing.JComboBox();
        jLabel16 = new javax.swing.JLabel();
        cboDayDlg = new javax.swing.JComboBox();
        cboYearDlg = new javax.swing.JComboBox();
        rdoToday = new javax.swing.JRadioButton();
        rdoAnotherDay = new javax.swing.JRadioButton();
        btnGo = new javax.swing.JButton();
        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup1.add(rdoToday);
        buttonGroup1.add(rdoAnotherDay);
        btnAdd = new javax.swing.JButton();
        btnUpdate = new javax.swing.JButton();
        btnReport = new javax.swing.JButton();
        pnScheduleList = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblScheduleList = new javax.swing.JTable();
        jLabel4 = new javax.swing.JLabel();
        btnRefresh = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        txtClass = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtSubject = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        txtUser = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        btnSearch = new javax.swing.JButton();
        dpStartSearch = new com.standbysoft.component.date.swing.JDatePicker();
        dpStartSearch.putClientProperty("JDatePicker.TimePickerUI", SpinnerTimePickerUI.class.getName());
        dpStartSearch.putClientProperty("JDatePicker.showTimePicker", Boolean.TRUE);
        dpStartSearch.setDateFormat(DATE_FORMAT);
        dpStartSearch.setEditable(true);
        dpStartSearch.setEmptySelectionText("<none>");

        dpEndSearch = new com.standbysoft.component.date.swing.JDatePicker();
        dpEndSearch.putClientProperty("JDatePicker.TimePickerUI", SpinnerTimePickerUI.class.getName());
        dpEndSearch.putClientProperty("JDatePicker.showTimePicker", Boolean.TRUE);
        dpEndSearch.setDateFormat(DATE_FORMAT);
        dpEndSearch.setEditable(true);
        dpEndSearch.setEmptySelectionText("<none>");

        pnScheduleInfo = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        cboClass = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        cboSubject = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        cboUser = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        dpEnd = new com.standbysoft.component.date.swing.JDatePicker();
        dpEnd.putClientProperty("JDatePicker.TimePickerUI", SpinnerTimePickerUI.class.getName());
        dpEnd.putClientProperty("JDatePicker.showTimePicker", Boolean.TRUE);
        dpEnd.setEditable(true);
        dpEnd.setDateFormat(DATE_FORMAT);
        dpStart = new com.standbysoft.component.date.swing.JDatePicker();
        dpStart.putClientProperty("JDatePicker.TimePickerUI", SpinnerTimePickerUI.class.getName());
        dpStart.putClientProperty("JDatePicker.showTimePicker", Boolean.TRUE);
        dpStart.setEditable(true);
        dpStart.setDateFormat(DATE_FORMAT);

        pnReport.setBackground(new java.awt.Color(255, 255, 255));

        jLabel5.setFont(new java.awt.Font("Tahoma", 2, 11));
        jLabel5.setText("Select an option :");

        pnToggle.setBackground(new java.awt.Color(255, 255, 255));

        jLabel16.setText("- Choose a specific day to view schedules then click Go again:");

        javax.swing.GroupLayout pnToggleLayout = new javax.swing.GroupLayout(pnToggle);
        pnToggle.setLayout(pnToggleLayout);
        pnToggleLayout.setHorizontalGroup(
                pnToggleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnToggleLayout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(pnToggleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(pnToggleLayout.createSequentialGroup()
                                                .addGap(10, 10, 10)
                                                .addComponent(cboMonthDlg, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(cboDayDlg, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(cboYearDlg, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(jLabel16))
                                .addContainerGap(30, Short.MAX_VALUE))
        );
        pnToggleLayout.setVerticalGroup(
                pnToggleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnToggleLayout.createSequentialGroup()
                                .addGap(26, 26, 26)
                                .addComponent(jLabel16)
                                .addGap(11, 11, 11)
                                .addGroup(pnToggleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(cboMonthDlg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(cboDayDlg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(cboYearDlg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap(47, Short.MAX_VALUE))
        );

        rdoToday.setBackground(new java.awt.Color(255, 255, 255));
        rdoToday.setSelected(true);
        rdoToday.setText("View all schedules of today");

        rdoAnotherDay.setBackground(new java.awt.Color(255, 255, 255));
        rdoAnotherDay.setText("Choose another day");

        btnGo.setText("Go");
        btnGo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnReportLayout = new javax.swing.GroupLayout(pnReport);
        pnReport.setLayout(pnReportLayout);
        pnReportLayout.setHorizontalGroup(
                pnReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnReportLayout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(pnReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel5)
                                        .addGroup(pnReportLayout.createSequentialGroup()
                                                .addGap(10, 10, 10)
                                                .addGroup(pnReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                        .addComponent(rdoAnotherDay, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                        .addComponent(rdoToday, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                        .addComponent(btnGo))))
                                .addContainerGap(160, Short.MAX_VALUE))
                        .addComponent(pnToggle, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        pnReportLayout.setVerticalGroup(
                pnReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnReportLayout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(rdoToday)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(rdoAnotherDay)
                                .addGap(18, 18, 18)
                                .addComponent(btnGo)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(pnToggle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pnToggle.setVisible(false);

        javax.swing.GroupLayout dlgReportLayout = new javax.swing.GroupLayout(dlgReport.getContentPane());
        dlgReport.getContentPane().setLayout(dlgReportLayout);
        dlgReportLayout.setHorizontalGroup(
                dlgReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(pnReport, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        dlgReportLayout.setVerticalGroup(
                dlgReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(pnReport, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        setBackground(new java.awt.Color(255, 255, 255));

        btnAdd.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/add-16.png"));
        btnAdd.setText("Add");
        btnAdd.setMaximumSize(new java.awt.Dimension(61, 23));
        btnAdd.setMinimumSize(new java.awt.Dimension(61, 23));
        btnAdd.setPreferredSize(new java.awt.Dimension(61, 23));
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        btnUpdate.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/update-16.png"));
        btnUpdate.setText("Update");
        btnUpdate.setMaximumSize(new java.awt.Dimension(71, 23));
        btnUpdate.setMinimumSize(new java.awt.Dimension(71, 23));
        btnUpdate.setPreferredSize(new java.awt.Dimension(71, 23));
        btnUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdateActionPerformed(evt);
            }
        });

        btnReport.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/printer-16.png"));
        btnReport.setText("Report");
        btnReport.setMaximumSize(new java.awt.Dimension(71, 23));
        btnReport.setMinimumSize(new java.awt.Dimension(71, 23));
        btnReport.setPreferredSize(new java.awt.Dimension(71, 23));
        btnReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReportActionPerformed(evt);
            }
        });

        pnScheduleList.setBackground(new java.awt.Color(255, 255, 255));
        pnScheduleList.setBorder(javax.swing.BorderFactory.createTitledBorder("Schedule list"));

        tblScheduleList.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][]{

                },
                new String[]{
                        "ID", "Class", "Subject", "User", "Start time", "End time"
                }
        ) {
            Class[] types = new Class[]{
                    java.lang.Integer.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.util.Date.class, java.util.Date.class
            };
            boolean[] canEdit = new boolean[]{
                    false, true, true, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        jScrollPane1.setViewportView(tblScheduleList);

        javax.swing.GroupLayout pnScheduleListLayout = new javax.swing.GroupLayout(pnScheduleList);
        pnScheduleList.setLayout(pnScheduleListLayout);
        pnScheduleListLayout.setHorizontalGroup(
                pnScheduleListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnScheduleListLayout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 475, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnScheduleListLayout.setVerticalGroup(
                pnScheduleListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnScheduleListLayout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(32, Short.MAX_VALUE))
        );

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 16));
        jLabel4.setForeground(new java.awt.Color(0, 102, 255));
        jLabel4.setText("MANAGE SCHEDULES");

        btnRefresh.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/refresh-16.gif"));
        btnRefresh.setText("Refresh");
        btnRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRefreshActionPerformed(evt);
            }
        });

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Search for schedule"));
        jPanel4.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jPanel4.setMaximumSize(new java.awt.Dimension(452, 219));
        jPanel4.setMinimumSize(new java.awt.Dimension(452, 219));

        jLabel10.setText("Class:");

        jLabel20.setText("Subject:");

        jLabel21.setText("End time:");

        jLabel22.setText("User:");

        jLabel23.setText("Start time:");

        btnSearch.setIcon(new ImageIcon(Settings.IMAGES_DIR + "/search-16.png"));
        btnSearch.setText("Search");
        btnSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchActionPerformed(evt);
            }
        });

        dpStartSearch.setEmptySelectionText("<none>");

        dpEndSearch.setEmptySelectionText("<none>");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel23)
                                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel22, javax.swing.GroupLayout.Alignment.TRAILING)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(txtUser)
                                        .addComponent(txtClass)
                                        .addComponent(dpStartSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                                                .addComponent(jLabel21)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(dpEndSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanel4Layout.createSequentialGroup()
                                                .addComponent(jLabel20)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(btnSearch)
                                                        .addComponent(txtSubject))))
                                .addContainerGap(20, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                                .addContainerGap(28, Short.MAX_VALUE)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel23)
                                        .addComponent(dpEndSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel21)
                                        .addComponent(dpStartSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel10)
                                        .addComponent(txtClass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel20)
                                        .addComponent(txtSubject, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel22)
                                        .addComponent(txtUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(btnSearch))
                                .addGap(38, 38, 38))
        );

        pnScheduleInfo.setBackground(new java.awt.Color(255, 255, 255));
        pnScheduleInfo.setBorder(javax.swing.BorderFactory.createTitledBorder("Add new schedule"));
        pnScheduleInfo.setPreferredSize(new java.awt.Dimension(452, 219));

        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel8.setText("Class:");

        cboClass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboClassActionPerformed(evt);
            }
        });

        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel9.setText("Subject:");

        cboSubject.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboSubjectActionPerformed(evt);
            }
        });

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel6.setText("User:");

        jLabel1.setText("End Time:");

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("Start time:");

        try {
            dpEnd.setEmptySelectionAllowed(false);
        } catch (com.standbysoft.component.date.DateSelectionException e1) {
            e1.printStackTrace();
        }

        try {
            dpStart.setEmptySelectionAllowed(false);
        } catch (com.standbysoft.component.date.DateSelectionException e1) {
            e1.printStackTrace();
        }

        javax.swing.GroupLayout pnScheduleInfoLayout = new javax.swing.GroupLayout(pnScheduleInfo);
        pnScheduleInfo.setLayout(pnScheduleInfoLayout);
        pnScheduleInfoLayout.setHorizontalGroup(
                pnScheduleInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnScheduleInfoLayout.createSequentialGroup()
                                .addGap(61, 61, 61)
                                .addGroup(pnScheduleInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel1)
                                        .addGroup(pnScheduleInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel6)
                                                .addComponent(jLabel8))
                                        .addComponent(jLabel2))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(pnScheduleInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(cboUser, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(pnScheduleInfoLayout.createSequentialGroup()
                                                .addGroup(pnScheduleInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                        .addComponent(dpStart, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                        .addComponent(dpEnd, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnScheduleInfoLayout.createSequentialGroup()
                                                                .addComponent(cboClass, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addGap(12, 12, 12)
                                                                .addComponent(jLabel9)))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(cboSubject, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addContainerGap(97, Short.MAX_VALUE))
        );
        pnScheduleInfoLayout.setVerticalGroup(
                pnScheduleInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnScheduleInfoLayout.createSequentialGroup()
                                .addGap(47, 47, 47)
                                .addGroup(pnScheduleInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel2)
                                        .addComponent(dpStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(pnScheduleInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(dpEnd, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING))
                                .addGap(18, 18, 18)
                                .addGroup(pnScheduleInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel8)
                                        .addComponent(cboClass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel9)
                                        .addComponent(cboSubject, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(pnScheduleInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel6)
                                        .addComponent(cboUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap(52, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                                .addContainerGap()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jLabel4)
                                                        .addGroup(layout.createSequentialGroup()
                                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                                        .addComponent(pnScheduleInfo, javax.swing.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE)
                                                                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                .addComponent(pnScheduleList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                        .addGroup(layout.createSequentialGroup()
                                                .addGap(333, 333, 333)
                                                .addComponent(btnAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(btnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(btnReport, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(btnRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addContainerGap(46, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(25, 25, 25)
                                .addComponent(jLabel4)
                                .addGap(29, 29, 29)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(pnScheduleInfo, javax.swing.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE))
                                        .addComponent(pnScheduleList, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(btnAdd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(btnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(btnReport, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(btnRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(65, 65, 65))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnAddActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        doAdd();
    }//GEN-LAST:event_btnAddActionPerformed

    private void btnUpdateActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnUpdateActionPerformed
        doUpdate();
    }//GEN-LAST:event_btnUpdateActionPerformed

    private void btnReportActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnReportActionPerformed
        dlgReport = new JDialog();
        dlgReport.setContentPane(pnReport);
        dlgReport.setLocationRelativeTo(null);
        dlgReport.setPreferredSize(new Dimension(350, 250));
        dlgReport.setModal(true);
        dlgReport.pack();
        dlgReport.setVisible(true);
    }//GEN-LAST:event_btnReportActionPerformed

    private void btnRefreshActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnRefreshActionPerformed
        refresh();
    }//GEN-LAST:event_btnRefreshActionPerformed

    private void btnSearchActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed
        doSearch();
    }//GEN-LAST:event_btnSearchActionPerformed

    private void cboClassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboClassActionPerformed
        if (cboSubject.getItemCount() != 0)
            cboSubject.removeAllItems();
        generateSubjectFromClass();
    }//GEN-LAST:event_cboClassActionPerformed

    private void cboSubjectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboSubjectActionPerformed
        if (cboUser.getItemCount() != 0)
            cboUser.removeAllItems();
        generateUserFromSubject();
    }//GEN-LAST:event_cboSubjectActionPerformed

    private void btnGoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGoActionPerformed
        ScheduleReporter sr = new ScheduleReporter();

        if (rdoToday.isSelected()) {
            try {
                sr.view();
            } catch (JRException ex) {
                Logger.getLogger(Schedule.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(Schedule.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (pnToggle.isVisible()) {
            String monthPattern = Helper.parsePattern("" + (cboMonthDlg.getSelectedIndex() + 1));
            String dayPattern = Helper.parsePattern("" + cboDayDlg.getSelectedItem());
            String date = monthPattern + dayPattern + cboYearDlg.getSelectedItem();
            sr.hasDate(Helper.toDate(date, "MMddyyyy"));

            try {
                sr.view();
            } catch (JRException ex) {
                Logger.getLogger(Schedule.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(Schedule.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else
            Helper.toggle(pnToggle);
    }//GEN-LAST:event_btnGoActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnGo;
    private javax.swing.JButton btnRefresh;
    private javax.swing.JButton btnReport;
    private javax.swing.JButton btnSearch;
    private javax.swing.JButton btnUpdate;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox cboClass;
    private javax.swing.JComboBox cboDayDlg;
    private javax.swing.JComboBox cboMonthDlg;
    private javax.swing.JComboBox cboSubject;
    private javax.swing.JComboBox cboUser;
    private javax.swing.JComboBox cboYearDlg;
    private javax.swing.JDialog dlgReport;
    private com.standbysoft.component.date.swing.JDatePicker dpEnd;
    private com.standbysoft.component.date.swing.JDatePicker dpEndSearch;
    private com.standbysoft.component.date.swing.JDatePicker dpStart;
    private com.standbysoft.component.date.swing.JDatePicker dpStartSearch;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel pnReport;
    private javax.swing.JPanel pnScheduleInfo;
    private javax.swing.JPanel pnScheduleList;
    private javax.swing.JPanel pnToggle;
    private javax.swing.JRadioButton rdoAnotherDay;
    private javax.swing.JRadioButton rdoToday;
    private javax.swing.JTable tblScheduleList;
    private javax.swing.JTextField txtClass;
    private javax.swing.JTextField txtSubject;
    private javax.swing.JTextField txtUser;
    // End of variables declaration//GEN-END:variables

}
